from django.db import models
from .user.models import UserInfo


class Roles(models.Model):
    name = models.CharField(verbose_name="名称", max_length=45, unique=True)
    status = models.BooleanField(verbose_name="是否可用", default=True)
    remarks = models.CharField(verbose_name="备注", max_length=1024, null=True, blank=True)

    class Meta:
        db_table = "user_roles"
        verbose_name = "角色表"
        verbose_name_plural = "角色表"


class UserRoles(models.Model):
    user_id = models.IntegerField(verbose_name="用户ID")
    role_id = models.IntegerField(verbose_name="角色ID")

    class Meta:
        db_table = "user_related_roles"
        verbose_name = "用户角色关联表"
        verbose_name_plural = "用户角色关联表"


class Menus(models.Model):
    title = models.CharField(verbose_name="路由标题", max_length=45, default="")
    name = models.CharField(verbose_name="名称", max_length=45, default="")
    alias = models.CharField(verbose_name="路由别名", max_length=128, default="")
    icon = models.CharField(verbose_name="图标", max_length=128, null=True, blank=True)
    sort = models.IntegerField(verbose_name="顺序", default=0)
    parent = models.IntegerField(verbose_name="父级", default=0)
    menu_type = models.IntegerField(verbose_name="菜单类型", default=1)  # 1 菜单， 2 按钮， 3 接口
    component = models.CharField(verbose_name="组件地址", max_length=128, null=True, blank=True)
    path = models.CharField(verbose_name="路由地址", max_length=128, null=True, blank=True)
    hidden = models.BooleanField(verbose_name="是否隐藏", default=False)
    external_link = models.BooleanField(verbose_name="是否外链", default=False)
    permission = models.CharField(verbose_name="权限标识", max_length=128, null=True, blank=True)
    method = models.CharField(verbose_name="请求方法", max_length=45, null=True, blank=True)
    no_cache = models.BooleanField(verbose_name="是否缓存", default=True)

    class Meta:
        db_table = "user_menus"
        verbose_name = "菜单表"
        verbose_name_plural = "菜单表"


# 角色与菜单关联表
class RoleMenus(models.Model):
    role = models.IntegerField(verbose_name="角色ID")
    menu = models.IntegerField(verbose_name="菜单ID")

    class Meta:
        db_table = "user_role_related_menus"
        verbose_name = "角色与菜单关联表"
        verbose_name_plural = "角色与菜单关联表"
